package com.luocj.muke.common.dialog.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.luocj.muke.common.net.Utils;

public class MyDialog extends Dialog {

    private Context                 mContext;
    private View                    inflate;
    private float                   dimAmount = .0f;
    private float                   width = 0.8f;
    private boolean                 cancelable = true;

    public float getDimAmount() {
        return dimAmount;
    }

    public void setDimAmount(float dimAmount) {
        this.dimAmount = dimAmount;
    }

    public float getWidth() {
        return width;
    }

    public void setWidth(float width) {
        this.width = width;
    }

    public boolean isCancelable() {
        return cancelable;
    }

    @Override
    public void setCancelable(boolean cancelable) {
        this.cancelable = cancelable;
    }

    //    private float height;

    @LayoutRes
    private int layoutId;

    public int getLayoutId() {
        return layoutId;
    }

    public void setLayoutId(int layoutId) {
        this.layoutId = layoutId;
    }

    public MyDialog(@NonNull Context context) {
        super(context);
        this.mContext = context;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        inflate = LayoutInflater.from(mContext).inflate(getLayouId(), null);
        setContentView(layoutId);
        Window window = getWindow();
        WindowManager.LayoutParams ab = window.getAttributes();
        ab.width = (int) (mContext.getResources().getDisplayMetrics().widthPixels * width);
        ab.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        ab.height = Utils.dip2px(mContext, 200);
        ab.dimAmount = dimAmount;
        setCancelable(cancelable);
        window.setGravity(Gravity.CENTER);
//        window.setBackgroundDrawable(new ColorDrawable(0));
        window.setAttributes(ab);
    }


    private int getLayouId() {
        return layoutId;
    }
}
